﻿Imports System.Security.Cryptography
'ESTA CLASE SOLO SE ESTA USANDO EL MODPARAMETROS.VB cuando tenga tiempo hay que eliminar 
'y ya no usar estas clases

Public Class ClsUsuario
    Inherits ClsSQL

    Private login As String
    Private password As String
    Private nombre As String
    Private super As Integer
    Dim estado As String
    Dim FechaRegistro As Date
    Dim usuario As String

#Region "Propiedades o Atributos"
    Property Plogin() As String
        Get
            Return login
        End Get
        Set(ByVal value As String)
            login = value
        End Set
    End Property
    Property Ppassword() As String
        Get
            Return password
        End Get
        Set(ByVal value As String)
            password = value
        End Set
    End Property
    Property Pnombre() As String
        Get
            Return nombre
        End Get
        Set(ByVal value As String)
            nombre = value
        End Set
    End Property

    Property Psuper() As Integer
        Get
            Return super
        End Get
        Set(ByVal value As Integer)
            super = value
        End Set
    End Property
    Property Pestado() As String
        Get
            Return estado
        End Get
        Set(ByVal value As String)
            estado = value
        End Set
    End Property
    Property Pfecharegistro() As Date
        Get
            Return FechaRegistro
        End Get
        Set(ByVal value As Date)
            FechaRegistro = value
        End Set
    End Property
    Property Pusuario() As String
        Get
            Return usuario
        End Get
        Set(ByVal value As String)
            usuario = value
        End Set
    End Property
#End Region

#Region "Procedmientos y Funciones"

    Sub ClsConectar(ByVal bd As String, Optional ByVal servidor As String = "")
        Select Case bd
            Case "administracion"
                Conectar(0)
            Case "corbol"
                Conectar(1)
            Case "importacion"
                Conectar(2)
            Case "corbol09"
                Conectar(3)
            Case "corbol2010"
                Conectar(4)
            Case "pruebas"
                Conectar(5)
            Case "corbol2011"
                Conectar(6)
        End Select
    End Sub

    Sub ClsDesConectar()
        Desconectar()
    End Sub

    Function ClsTraerTabla(ByVal opcion As Int16, Optional ByVal filtro As String = "") As DataTable
        Select Case opcion
            Case 0
                Return TraerTabla("VUSUARIO", "*")
            Case 1
                Return Buscador("VUSUARIO", "WHERE LOGIN='" & Plogin & "' AND CodEmpresa=" & Pestado)
            Case 2
                Return Buscador("ADMENU", "WHERE " + filtro)
            Case 3
                Return Buscador("VOPCION", "WHERE USUARIO='" & Plogin & "' AND OPCION='" & filtro & "' AND ACCESO=1")
            Case 4
                Return Buscador("VOPCION", "WHERE USUARIO='" & Plogin & "'")
        End Select
    End Function
    Function ClsTraerTablaDs(Optional ByVal opcion As Integer = 0) As DataSet
        Select Case opcion
            Case 0
                Return TraerTablaDs("VUSUARIO", "*", " ESTADO<>1 AND CodEmpresa=" & Pestado)
        End Select
    End Function

    Public Function Encriptar(ByVal Password) As String
        Dim valorhash As New SHA1CryptoServiceProvider()
        Dim valorbyte() As Byte = Text.Encoding.UTF8.GetBytes(Password)
        Dim bytehash() As Byte = valorhash.ComputeHash(valorbyte)
        valorhash.Clear()
        Return Convert.ToBase64String(bytehash)
    End Function
#End Region
End Class
